
/*
 * Requests the metadata for the list of gadgets contained in gadgetData
 * 
 * Successful metadata request results in a call to generateGadgets which
 * will generate the gadgets for display.
 * 
 * gadget_data is an array like the sample below:
 * 		gadget_data = [
 * 						{
 *							url: spec_url, 
 *							container_id: container_id,
 *							moduleId: 1 },
 * 						{
 *							url: spec_url, 
 *							container_id: container_id,
 *							moduleId: 1 },	
 * 					];
 */
function request_metadata(context, gadget_data, success_callback, error_callback) {
	var metadata_params = {"context": context,
						   "gadgets": gadget_data};
				
	alert('params = ' + dojo.toJson(metadata_params))			   
	var url = gadget_server_host + '/gadget/metadata';
	dojo.xhrPost({
	    url: url,
		postData: 'json=' + dojo.toJson(metadata_params),
	    timeout: 6000, // give up after 6 seconds
		load: success_callback,
		error: error_callback
	});
}


function render_gadget(iframe_url) {
  	content = '<div><iframe src="' + iframe_url +
      '" width="400" height="600" frameborder="no" scrolling="no"></iframe></div>';
	return content;
};


/*
 * Calls the gadget server to render a gadget.
 */
/*function render_gadget(iframe_url) {
	dojo.xhrPost({
	    url: gadget_server_host + iframe_url,
	    timeout: 30000, // give up after 3 seconds
		load: function (data) {render_gadget_success(data);},
		error: function (error) {render_gadget_error(error);}
	});
}*/